package admin.sys;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.CommonUtil;
import com.common.MD5;
import com.common.ResultData;
import com.filter.BaseController;

import beans.sys.SYSCodeBean;
import beans.sys.SysCodeModel;
import service.sys.SYSCodeServiceImpl;

@Controller
@RequestMapping("/selfhelp")
public class SelfhelpController extends BaseController {
	@Autowired
	private SYSCodeServiceImpl sysCodeServiceImpl;

	@RequestMapping("/list")
	public String Index(String type){
		getReq().setAttribute("code", type);
		return "admin/sys/selfhelp/index";
	}

	@RequestMapping("/griddata")
	@ResponseBody
	public void DataGrid(SysCodeModel model){
		ResultData<List<Map>> rd = new ResultData<>();
		try{
			List<Map> m = sysCodeServiceImpl.queryByList(model);
			rd.setRows(m);
			rd.setTotal(model.getPager().getRowCount());
		}
		catch(Exception e){
			e.printStackTrace();
		}
		responseJson(rd);
	}

	@RequestMapping("/detail")
	public String Detail(String id,String culType){
		if(!CommonUtil.isNullObject(id)){
			try {
				SYSCodeBean m = (SYSCodeBean)sysCodeServiceImpl.queryById(id);
				getReq().setAttribute("mm", m);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "admin/sys/selfhelp/detail";
	}

	@RequestMapping("/save")
	@ResponseBody
	public void Save(SYSCodeBean m){
		ResultData<String> rd = new ResultData<>();
		try {
			sysCodeServiceImpl.update(m);
			rd.setType(1);
			rd.setMessage("保存成功");
		} catch (Exception e) {
			e.printStackTrace();
			rd.setMessage("保存失败");
		}
		responseJson(rd);
	}
	
	@RequestMapping("/getList")
	@ResponseBody
	public void getList(String code){
		try{
			List<Map> m = sysCodeServiceImpl.getListByCode(code);
			responseJsonArray(m);
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}
